home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / docs / hdfvset.lha / HDFVset.ch1 < prev    next >
Text File  |  1994-01-10  |  24KB  |  694 lines

  1. 1.1    NCSA HDF Vset
  2.  
  3.  
  4. NCSA HDF Vset Basics    1.1
  5.  
  6.  
  7. National Center for Supercomputing Applications
  8.  
  9. November 1990
  10.  
  11.                                                                 
  12.  
  13.  
  14.  
  15.  
  16.  
  17. 1.1    NCSA HDF Vset
  18.  
  19.  
  20. NCSA HDF Vset Basics    1.1
  21.  
  22.  
  23. National Center for Supercomputing Applications
  24.  
  25. November 1990
  26.  
  27.                                                                 
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. Chapter 1    NCSA HDF Vset Basics
  37.  
  38.  
  39.  
  40. Chapter Overview
  41. Understanding NCSA HDF Vset
  42. Deciding on a Vset Scheme
  43. Examining the HDF Vset Interface
  44. Using Examples
  45. Example 1:  Writing Data
  46. Example 2:  Reading Data
  47. Example 3:  Using Meshes and Connectivity 
  48.         Lists
  49. Example 4:  Linking Vset Elements 
  50. Using the HDF Vset Routines
  51. Naming Vgroups and Vdatas
  52.  
  53. Chapter Overview
  54.  
  55. This chapter introduces the NCSA HDF Vset and presents several 
  56. examples on reading and writing data using the vset interface.
  57.  
  58.  
  59. Understanding NCSA HDF Vset
  60.  
  61. An HDF Vset is a logical grouping of diverse, but related data 
  62. items within an HDF file. Data organization within the file 
  63. resembles the UNIX file system. Only two basic types of storage 
  64. elements exist in a vset:  vgroups and vdatas. A vgroup is like a 
  65. directory or subdirectory, while a vdata is like a file. Thus, a vdata 
  66. may only contain data, while a vgroup only contains references to 
  67. vdatas or to other vgroups. The entire vset may be viewed as a 
  68. directory tree with vgroups as nodes and vdatas as leaves. Figure 
  69. 1.1 shows a vset with data stored in five vdatas while Figure 1.2 
  70. shows two vsets in an open file. Note that several vgroups may 
  71. point to the same vgroup or vdata.
  72.  
  73. Vdatas only store data. The data is organized into fields within 
  74. each vdata. Each field is identified by a unique fieldname. The 
  75. type of each field may be either integer, character or float. Fields of 
  76. different types may exist within a vdata.
  77.  
  78. Figure 1.1    Analogy Between the HDF Vset and the UNIX File System
  79.  
  80.  
  81.                                                                  
  82. Figure 1.2    Sharing Data Among Vsets
  83.  
  84.                                             
  85.  
  86.  
  87. Deciding on a Vset Scheme
  88.  
  89. The HDF Vset is a versatile hierarchical storage scheme for 
  90. grouping simple or multi-dimensional datasets. Multi-variable 
  91. datasets are conveniently stored as vsets by first identifying the 
  92. fields in the datasets. 
  93.  
  94. As many fields as needed may be defined for storing data in a 
  95. vset. There are many ways of organizing these fields. At one 
  96. extreme, all the fields are organized in one huge vdata (vset C in 
  97. Figure 1.3). At the other extreme, data for one field is stored in one 
  98. vdata (vset B in Figure 1.3). Usually, closely related fields are 
  99. organized together in one vdata (vset A in Figure 1.3).
  100.  
  101. After all the fields are organized into vdatas, vgroups should 
  102. always be used to group the vdatas in a hierarchical manner. 
  103. Vdatas that are related should be grouped together. Since it is 
  104. possible for several vdatas to point to one vgroup or vdata, a well-
  105. chosen grouping saves on file storage by avoiding duplication of 
  106. data. Figure 1.4 shows an HDF file containing three vsets. The 
  107. three vsets have one vdata in common.
  108.  
  109. Figure 1.3    Vset Schemes
  110.  
  111.                                                                  
  112.  
  113.  
  114.  
  115.                                                               
  116.  
  117.  
  118. Figure 1.4    HDF File with Three Vsets
  119.  
  120.  
  121.                                                                      
  122.  
  123.  
  124. In this file, three vsets exist, each consisting of one vgroup 
  125. referencing two vdatas. The vgroups are named "result 1," 
  126. "result 2," and "result 3," respectively. Since the positional 
  127. values do not change during the simulation, only one vdata, 
  128. defined to contain the fields "PX, PY," is needed. The three vsets 
  129. then "share" this vdata. On the other hand, the temperature values, 
  130. different for each time, are stored as three separate vdatas, each 
  131. defined to contain the field "TMP" for temperature.
  132.  
  133.  
  134. Examining the HDF Vset Interface
  135.  
  136. The HDF Vset interface is a library of routines for the definition, 
  137. organization, and manipulation of vgroups and vdatas, as well as 
  138. for data access. The routines are classified according to the action 
  139. they perform:
  140.  
  141. Table 1.1    Vset Routines
  142. Ñ    access    grants or terminates access to vgroups or vdatas.
  143. Ñ    inquiry    returns information about vgroups or vdatas.
  144. Ñ    search    searches and locates specific vgroups or vdatas.
  145. Ñ    specify    sets up specification for data access.
  146. Ñ    read/write    retrieves/stores data from/in vdatas.
  147. Ñ    linkage    links vgroups and vdatas to form vsets.
  148.  
  149.  
  150. Using Examples
  151.  
  152. The following examples demonstrate the ease in reading and 
  153. writing data using the vset interface routines. (See Appendix D 
  154. "Source Files," on compiling and creating executables.)
  155.  
  156.  
  157. Example 1:
  158. Writing Data
  159. Figure 1.5 shows a simple program that stores data as a vset in an 
  160. HDF file. It takes pxy, a 2D array (float) of 1000 points (x, y 
  161. values), and pv, an array (float) of 1000 temperature values, and 
  162. stores them as two vdatas linked to a vgroup (vset A in Figure 1.3). 
  163. One vdata is defined to contain one field, "TMP," for temperature, 
  164. while the other is defined to contain two fields, "PX, PY," for the 
  165. positional values. The vgroup is named "mypoints."
  166.  
  167. Figure 1.5    Storing Vset Data
  168.  
  169.     #include "vg.h"
  170.  
  171.     main()     {
  172.  
  173.         VGROUP        *vg;
  174.         VDATA        *vs;
  175.         DF        *f;
  176.         float        pxy[1000][2], temp[1000]; /* (x,y) temperature values */
  177.  
  178.  
  179.         f = DFopen("myfile.hdf", DFACC_ALL,0); /* open HDF file with full access */
  180.  
  181.         /* create a vgroup with write access, then name it "mypoints" */
  182.             vg = (VGROUP*) Vattach(f, -1,"w");    
  183.             Vsetname(vg,"mypoints");        
  184.  
  185.         /* create a vdata to store x,y values */
  186.             vs = (VDATA*) VSattach(f,  -1, "w");
  187.             VSsetfields(vs, "PX,PY");
  188.             VSwrite(vs, pxy, 1000, FULL_INTERLACE);
  189.             Vinsert(vg, vs);
  190.             VSdetach(vs);
  191.  
  192. Figure 1.5    Storing Vset Data (Continued)
  193.  
  194.         /* create a vdata to store temperature values */
  195.             vs = (VDATA*) VSattach(f, -1, "w");
  196.             VSfdefine (vs, "TMP",  LOCAL_FLOATTYPE,1);
  197.             VSsetfields(vs, "TMP");
  198.             VSwrite(vs, tmp, 1000, FULL_INTERLACE);
  199.             Vinsert(vg, vs);
  200.             VSdetach(vs);
  201.     
  202.         Vdetach(vg);
  203.         DFclose(f);
  204.         }
  205.  
  206.  
  207. The program in Figure 1.5 does the following:
  208.  
  209. 1.    The HDF file is opened.
  210.  
  211. 2.    A new vgroup is created by calling Vattach with an id 
  212. argument of -1. This vgroup is then named ╥mypoint.╙
  213.  
  214. 3.    A new vdata is created by VSattach with an id of -1. 
  215.  
  216. 4.    VSsetfields specifies that the vdata will contain two float 
  217. fields "PX, PY".
  218.  
  219. 5.    VSwrite writes out the data as 1,000 pairs of x, y values.
  220.  
  221. 6.    Vinsert establishes a link from the vgroup "mypoints" to this 
  222. vdata.
  223.  
  224. 7.    Access to the vdata is terminated with VSdetach.
  225.  
  226. 8.    A similar sequence of calls creates a second vdata, specifies 
  227. that it contains the field "TMP," writes out the temperature 
  228. values, links the same vgroup to the vdata, and detaches the 
  229. vdata.
  230.  
  231. 9.    Finally the vgroup itself is detached, and the HDF file is closed.
  232.  
  233. The fieldnames "PX" and "PY" are names pre-defined by the 
  234. interface to represent x and y float values. However, the fieldname 
  235. "TMP" is not pre-defined and it must first be defined with a 
  236. VSfdefine call specifying that "TMP" is a field of one float value. 
  237. (See Appendix C "Pre-defined Fieldnames," for a list of all pre-
  238. defined fieldnames.)
  239.  
  240. Each call to Vattach and VSattach returns a pointer to a vgroup 
  241. and vdata, respectively. The other routines then manipulate the 
  242. vgroups and vdatas through these pointers.
  243.  
  244. The fourth argument to VSwrite is the buffer interlace, a 
  245. parameter that tells VSwrite how data in the buffer is laid out. A 
  246. value of NO_INTERLACE specifies that all the data values for one 
  247. field are contiguous, while a value of FULL_INTERLACE specifies 
  248. that one data value of a field is immediately followed by one data 
  249. value of another field. 
  250. The vdata in the file also has its own interlace, called file 
  251. interlace, which equals FULL_INTERLACE by default. Chapter 2, 
  252. "Vdatas," describes buffer and file interlacing in detail.
  253.  
  254.  
  255. Example 2:  Reading Data
  256. The program in Figure 1.6 reads the data from the HDF file 
  257. created by the program in Figure 1.5. Assume it is known that a 
  258. vgroup exists named "mypoints" in the HDF file, and that this 
  259. vgroup contains (x, y) coordinate values in its first vdata and 
  260. temperature values in its second vdata; but, it is not known how 
  261. many vertices exist (vset A in Figure 1.3).
  262.  
  263. Figure 1.6    Reading Data from a Vset
  264.  
  265.     #include "vg.h"
  266.     main() {
  267.  
  268.         VGROUP        *vg;
  269.         VDATA         *vs;
  270.         DF        *f;
  271.         float        (*pxy)[2]; /* pointer to an array of 2 floats  (x,y coords) */
  272.         float        *temp;     /* pointer to an array of floats  (temperature ) */
  273.         int        nvertices, vsize, interlace;
  274.         char        vsname[50], vgname[50], fields[50];
  275.         int        vsid, vgid;    
  276.  
  277.  
  278.         f = DFopen("myfile.hdf", DFACC_ALL,0); /* open HDF file with full access */
  279.     
  280.  
  281.         /* first , locate that vgroup. set vgid to -1 to begin search */
  282.             vgid = -1;
  283.             while ((vgid=Vgetid(f, vgid)) != -1) {    
  284.                 vg = Vattach(f, vgid,"r");     /* attach with read access */
  285.                 Vgetname(vg, vgname);
  286.                 if (!strcmp(vgname,"mypoints"))  
  287.                     {  found = 1;  break; }    /* found the vgroup */
  288.                 Vdetach(vg); 
  289.                 }
  290.             if (found == 0) perror ("did not find vgroup. exit");
  291.         /*  next, extract the (x,y coords) from the  1st vdata */
  292.             vsid = -1;
  293.             vsid = Vgetnext(vg, vsid);        
  294.             vs = (VDATA*) VSattach(f, vsid, "r");
  295.             VSinquire(vs, &nvertices, &interlace, fields, &vsize, vsname);
  296.             pxy = (float*) malloc(nvertices * sizeof(float) * 2);        
  297.             VSsetfields(vs,"PX,PY");
  298.             VSread(vs, pxy,nvertices, FULL_INTERLACE);
  299.             VSdetach(vs);
  300.  
  301.         /*  finally extract the temperature values from the 2nd vdata */
  302.             vsid = Vgetnext(vg, vs id);             
  303.             vs = (VDATA*) VSattach(f, vsid, "r");
  304.             VSinquire(vs, &nvertices, &interlace, fields, &vsize, vsname);
  305.             temp  = (float*) malloc(nvertices  * sizeof(float) );        
  306.          
  307.             Vsetfields(vs,"TMP");
  308.             VSread(vs, temp, nvertices, FULL_INTERLACE);
  309.             VSdetach(vs);
  310.         Vdetach(vg);
  311. Figure 1.6    Reading Data from a Vset (Continued)
  312.  
  313.         DFclose(f);
  314.          ...
  315.         free(pxy);
  316.         free(temp);
  317.  
  318.         }
  319.  
  320.  
  321. The above program illustrates the following:  (1) searching for a 
  322. specific vgroup, (2) performing inquiries, and (3) determining the 
  323. amount of memory space to allocate.
  324.  
  325. The program does the following:
  326.  
  327. 1.    The HDF file is first opened.
  328.  
  329. 2.    It searches the HDF file for a vgroup named "mypoints" by 
  330. sequencing through all vgroups in a loop. The search is 
  331. initiated by setting the vgid argument to -1 in the call to Vgetid.
  332.  
  333. 3.    The call returns an id of a vgroup or -1 if none exists. 
  334. Whenever a vgroup id is returned, an attach is done to that 
  335. vgroup, and its name, as returned by Vgetname, is checked. A 
  336. flag is set if the vgroup is found.
  337.  
  338. 4.    Once the vgroup is found, its first vdata is attached. The call to 
  339. VSattach requires an id, which is obtained by a call to 
  340. Vgetnext. Vgetnext returns the id of the first vdata, if its id 
  341. argument is -1.
  342.  
  343. 5.    VSinquire returns, among other information, the number of 
  344. elements stored in that vdata. This number multiplied by the 
  345. size of an element (two floats) gives the size of the allocated 
  346. space.
  347.  
  348. 6.    VSsetfields then specifies that the data fields "PX, PY" in that 
  349. vdata will be accessed.
  350.  
  351. 7.    VSread reads the data into the allocated space, pxy.
  352.  
  353. 8.    The vdata is detached when reading is completed.
  354.  
  355. 9.    A similar sequence of calls extracts the temperature values 
  356. from the second vdata into the allocated space, temp. Note the 
  357. use of Vgetnext, which is being passed the id of the first vdata. 
  358. This call returns the id of the next entity after the first vdata. 
  359.  
  360.  
  361. Example 3:  Using Meshes 
  362. and Connectivity Lists
  363. Many scientific and graphic applications use meshes to describe 
  364. surfaces and objects as well as their properties. The shape of the 
  365. surfaces and objects are defined as a set of connected points or 
  366. nodes. The properties of the mesh are values attached to each node 
  367. or group of nodes within the mesh.
  368.  
  369. The HDF Vset allows the mesh description to be stored together with 
  370. its associated values. One way to represent and store meshes in an 
  371. HDF file is to define a vertex-set. A vertex-set is an instance of an 
  372. HDF Vset that, minimally, consists of the three following 
  373. component datasets:
  374.  
  375. 1.    A set containing the coordinates of the nodes in the mesh
  376.  
  377. 2.    A set that describes how the nodes are connected to each other to 
  378. form the shape of the mesh
  379.  
  380. 3.    One or more sets of data values that correspond to each of the 
  381. nodes or polygons
  382.  
  383. The second dataset is a matrix called a connectivity list. Each 
  384. element in a connectivity list describes a polygon within the mesh. 
  385. Each polygon is a list of all the nodes that form the polygon. The 
  386. connectivity list, then, is a set of polygons that form the mesh. Each 
  387. of the above component sets may be stored as a separate vdata. 
  388. These vdatas should then be grouped together with other descriptive 
  389. or annotative information under a vgroup.
  390.  
  391. As an example, assume that the 1000 nodes in Figure 1.3 actually 
  392. form a mesh of 400 triangles (Figure 1.7). (Each node has a node 
  393. number in addition to its coordinate position.) The connectivity of 
  394. the mesh is described by an array of node numbers, in the array 
  395. mesh. Every three numbers in one row of the table define a 
  396. triangle. This information can be stored as a connectivity list in 
  397. another vdata, as the user-defined field "PLIST" (polygon list). 
  398. The data can then be related to the position and temperature values 
  399. by linking the vdata to the existing vgroup (of vset A in Figure 1.3).
  400.  
  401. Figure 1.7    Mesh and Connectivity List 
  402.  
  403.  
  404.                                                                 
  405.  
  406.  
  407. The program in Figure 1.5 is easily modified to write a vertex-set 
  408. into an HDF file by adding code to store the connectivity list in the 
  409. same vset. 
  410.  
  411. The following code segment (Figure 1.8) stores the connectivity 
  412. list (i.e., the array mesh) into the vset A in Figure 1.3, thereby 
  413. creating the mesh vset as shown in Figure 1.7.
  414.  
  415. Figure 1.8    Storing a Connectivity List
  416.  
  417.         int mesh[400][3];
  418.             .....
  419.         /* create a vdata to store mesh  */
  420.             vs = (VDATA*) VSattach(f,  -1, "w");
  421.             VSfdefine (vs, "PLIST",  LOCAL_INTTYPE, 3);
  422.             VSsetfields(vs, "PLIST");
  423.             VSwrite(vs, mesh, 400, FULL_INTERLACE);
  424.             Vinsert(vg, vs);
  425.             VSdetach(vs);
  426.             .....
  427.  
  428.  
  429. This code segment should be inserted just before the Vdetach (vg) 
  430. statement in the program in Figure 1.5.
  431.  
  432. The connectivity list is stored in a new vdata that is then linked to 
  433. the vgroup of vset A. Creating and storing connectivity 
  434. information to a vdata is no different than the storing position and 
  435. temperature values in the program. (See the outlined steps below.)
  436.  
  437. 1.    The code creates a new vdata.
  438.  
  439. 2.    VSfdefine defines "PLIST" as one field comprising three 
  440. integers. This step is necessary because "PLIST" is not a pre-
  441. defined fieldname. VSsetfields then sets up the vdata to 
  442. contain this field.
  443.  
  444. 3.    VSwrite writes out the connectivity data for 400 triangles from 
  445. the array mesh into the vdata.
  446.  
  447. 4.    Vinsert links this vdata to the same vgroup.
  448.  
  449. 5.    VSdetach terminates access to this vdata. The resulting 
  450. configuration is shown in Figure 1.7.
  451.  
  452. Note that "PLIST" is a single field comprising three integers; 
  453. hence, the call to VSfdefine with the fourth argument equal to 3. 
  454. This argument specifies the order of the field. "PLIST", as defined 
  455. for this vertex-set, is a single field of order 3. Although one 
  456. "PLIST" element comprises three integers, these three integer 
  457. values can only be accessed together. Thus the following code 
  458. segment writes out three integer values; i.e.,  mesh[0][0], 
  459. mesh[0][1] and mesh[0][2]. (The numbers of the three nodes 
  460. form the first mesh triangle.)
  461.  
  462.         VSsetfields(vs, "PLIST");
  463.         VSwrite (vs, mesh, 1, interlace);
  464.  
  465.  
  466. Similarly in the code segment below, the call to read one ╥PLIST╙ 
  467. element from the vdata returns three integers (the numbers of the 
  468. three nodes forming this first mesh triangle) in the array x:
  469.  
  470.         int x[3];
  471.         ...
  472.         VSsetfields(vs, "PLIST");
  473.         VSread (vs, x, 1, interlace);
  474.  
  475.  
  476. Example 4:  Linking 
  477. Storage Elements in Vsets
  478. The program segment in Figure 1.9 illustrates the use of the 
  479. routine Vinsert. This routine allows several vgroups to refer to 
  480. one vdata in the HDF file, and hence, "share" data within the 
  481. vdata.
  482.  
  483. The dataset comprises pxy, a 2D array (float) of 1000 points 
  484. (x, y coordinates) and  three arrays t1, t2, and t3, each an array 
  485. (float) of 1000 temperature values taken from a simulation at three 
  486. different times. The points remain constant at all times. This 
  487. dataset is best represented  by three vsets, each representing the 
  488. simulation at a different time (vset B in Figure 1.3). Thus, four 
  489. vdatas exist, one for each temperature dataset and the fourth for the 
  490. points (x, y coordinates).
  491.  
  492. Figure 1.9    Linking Vgroups 
  493. and Vdatas
  494.  
  495.     #include "vg.h"
  496.  
  497.     main() {
  498.         VGROUP              *vg1, *vg2, *vg3;
  499.         VDATA             *vs;
  500.         DF                     *f;
  501.         int             b,n;
  502.  
  503.         float           pxy[1000][2];                    /* (x,y) values */
  504.         float           t1[1000], t2[1000], t3[1000]; /* temperature values */
  505.  
  506.         /* open HDF file */
  507.                     f = (DF*) DFopen("myfile.hdf", DFACC_ALL,0);
  508.  
  509.         /* attach a 3 new  vgroups with write access */
  510.             vg1 = (VGROUP*) Vattach(f, -1,"w");
  511.                     Vsetname(vg1, "result1");            /* name it "result1" (optional)*/
  512.                 vg2 = (VGROUP*) Vattach(f, -1,"w");
  513.             Vsetname(vg2, "result2");            /* name it "result2" (optional)*/
  514.                 vg3 = (VGROUP*) Vattach(f, -1,"w");
  515.                 Vsetname(vg3, "result3");          /* name it "result3" (optional)*/
  516.  
  517.         /* attach a new vdata to store temperature values t1. Insert into vg1. */
  518.                 vs = (VDATA*) VSattach(f, -1, "w");
  519.                b = VSfdefine (vs, "TMP",  LOCAL_FLOATTYPE, 1);
  520.                 b = VSsetfields(vs,"TMP");
  521.                 n = VSwrite(vs, t1, 1000, FULL_INTERLACE);
  522.              Vinsert(vg1, vs);
  523. Figure 1.9    Linking Vgroups 
  524. and Vdatas 
  525. (Continued)
  526.  
  527.                VSdetach(vs);
  528.  
  529.         /* attach a new vdata to store temperature values t2. Insert into vg2. */
  530.                 vs = (VDATA*) VSattach(f, -1, "w");
  531.                 b = VSfdefine (vs, "TMP",  LOCAL_FLOATTYPE, 1);
  532.                 b = VSsetfields(vs,"TMP");
  533.                 n = VSwrite(vs, t2,1000, FULL_INTERLACE);
  534.             Vinsert(vg2, vs);
  535.                VSdetach(vs);
  536.  
  537.         /* attach a new vdata to store temperature values t3. Insert into vg3. */
  538.                 vs = (VDATA*) VSattach(f, -1, "w");
  539.                 b = VSfdefine (vs, "TMP",  LOCAL_FLOATTYPE, 1);
  540.                b = VSsetfields(vs,"TMP");
  541.                n = VSwrite(vs, t3,1000, FULL_INTERLACE);
  542.             Vinsert(vg3, vs);
  543.                VSdetach(vs);
  544.  
  545.         /* attach a new vdata to store (x,y) values */
  546.         /*This vdata will be shared by the three vgroups */
  547.                 vs = (VDATA*) VSattach(f, -1, "w");
  548.                 b = VSsetfields(vs,"PX,PY");
  549.                n = VSwrite(vs, pxy,1000, FULL_INTERLACE);
  550.  
  551.         /* Insert  vs into vgroups vg1, vg2, and vg3, then detach it. */
  552.                 b = Vinsert(vg1, vs);
  553.                b = Vinsert(vg2, vs);
  554.                b = Vinsert(vg3, vs);
  555.             VSdetach(vs);
  556.  
  557.         /* done, detach all vgroups */
  558.                  Vdetach(vg1);
  559.             Vdetach(vg2);
  560.                  Vdetach(vg3);
  561.  
  562.                DFclose(f);
  563.         }
  564.  
  565.  
  566. The above code segment does the following:
  567.  
  568. 1.    The HDF file is opened.
  569.  
  570. 2.    Three new vgroups are created and attached.
  571.  
  572. 3.    Three separate vdatas are created and attached. Separate sets of 
  573. temperature data from t1, t2, and t3 are then written to each 
  574. vdata.
  575.  
  576. 4.    Each vdata is then linked to the respective vgroups using 
  577. Vinsert. After this step, the three vdatas are then detached.
  578.  
  579. 5.    A fourth vdata is created and attached for storing positional 
  580. data. Immediately after data is written to it, the three calls to 
  581. Vinsert each create a link from each of the three vgroups to this 
  582. vdata. The vdata is then detached.
  583. 6.    All vgroups are  detached and the file is closed.
  584.  
  585. After the insertions, each vgroup logically owns two vdatas. Note 
  586. that the shared vdata may be accessed by accessing any of the 
  587. vgroups╤the vdata now belongs equally to all three vgroups.
  588.  
  589. Vinsert may also be used to insert one vgroup into another vgroup 
  590. in a similar manner.
  591.  
  592.  
  593. Using the HDF Vset Routines
  594.  
  595. All the vset routines require that the HDF file be opened using 
  596. DFopen with the access-mode DFACC_ALL. The routines provide six 
  597. basic functions:  search, access, inquiry, specify, 
  598. read/write, and linkage:
  599.  
  600. Ñ    Search routines provide a systematic way of searching through 
  601. the HDF file for vgroups and vdatas.
  602.  
  603. Ñ    Access routines attach, or grant access to, vgroups or vdatas 
  604. before any data transfer can occur. They also detach, or 
  605. properly terminate access to, vgroups or vdatas when data 
  606. transfer is completed.
  607.  
  608. Ñ    Inquiry routines return information about existing vgroups or 
  609. vdatas. They are useful for searching through the file for a 
  610. specific vgroup or vdata, and for determining the fields and 
  611. data sizes of vdatas.
  612.  
  613. Ñ    Specify routines define and set up parameters that dictate the 
  614. format and amount of data to be read or written. They are also 
  615. used to define new fields and to assign names to vgroups and 
  616. vdatas.
  617.  
  618. Ñ    Read/Write routines perform the actual data transfer between 
  619. the file and the calling program. They are always preceded by 
  620. the appropriate access and specify routines.
  621.  
  622. Ñ    Linkage routines link vgroups with vdatas or other vgroups into 
  623. a hierarchy that is the vset.
  624.  
  625. The examples in this chapter are typical of the order for calling the 
  626. routines. In most cases, you will use the routines in the following 
  627. order:
  628.  
  629. Ñ    Search for a vgroup.
  630.  
  631. Ñ    Attach a vgroup, a procedure that returns a pointer  to a vgroup.
  632.  
  633. Ñ    Sequence through that vgroup and search for the desired vdata. 
  634. Vgroups that are attached to the vgroup should be similarly 
  635. searched.
  636. Ñ    Attach the desired vdata when found.
  637.  
  638. Ñ    Execute inquiry calls at any time, to get information about 
  639. existing vgroups or vdatas (e.g., its name, fieldnames, element 
  640. size, interlace, etc).
  641.  
  642. Ñ    Perform a series of specify calls on the vdatas to establish the 
  643. fields to be accessed and the type of interlace used. The specify 
  644. calls must be performed before any data transfer can occur. For 
  645. more information on interlace, see Chapter 2, ╥Vdatas.╙
  646.  
  647. Ñ    Execute a series of read/write calls to read or write data.
  648. Ñ    Link newly created vgroups or vdata into new or existing 
  649. vgroups or vdatas.
  650.  
  651. Ñ    Perform a detach to terminate access to every vdata or vgroup 
  652. that was attached when linkage is completed.
  653.  
  654. Ñ    Use the access routine VSseek, if necessary, for random-access 
  655. reads within a vdata. (NOTE:  Random-access writes are 
  656. forbidden.)
  657.  
  658. Ñ    Close the HDF file by calling DFclose.
  659.  
  660.  
  661. Naming Vgroups and Vdatas
  662.  
  663. When there is more than one vgroup or vdata within a file, a 
  664. problem arises:  How can one uniquely identify or refer to a 
  665. particular vgroup or vdata? One way to solve the problem is to 
  666. always name each vgroup or vdata. (Using Vsetname and 
  667. VSsetname). Assigning a unique name enables you to easily 
  668. identify vgroups or vdatas in the future. The routines Vgetname 
  669. and VSgetname each return the name of a vgroup or vdata, 
  670. respectively. Thus, rather than guessing which vgroup or vdata to 
  671. use, you use its name for searching. 
  672.  
  673. Naming vgroups or vdatas is optional. Vgroups or vdatas may also 
  674. be located if their identifiers are known. The identifiers are 
  675. unique, and are actually the reference component of their HDF 
  676. tag-ref identifiers. They are values used and returned by the 
  677. search routines (Vgetid, VSgetid, Vgetnext).
  678.  
  679. 1.    Pass an identifier of -1 to the search routine. The routine then 
  680. returns the identifier of the first vgroup or vdata.
  681.  
  682. 2.    Pass the returned identifier back to the routine. This will then 
  683. return the identifier of the next vgroup or vdata. No more 
  684. vgroups or vdatas are found if the routine returns -1.
  685.  
  686. 3.    Use the valid returned identifier in an attach call in order to 
  687. access that vgroup or vdata. 
  688.  
  689. Within a vgroup, there may be vdatas and other vgroups. The 
  690. identifier itself does not identify if an entity is a vdata or vgroup. 
  691. The inquiry routines Visvg and Visvs respectively test if an id 
  692. refers to a vgroup or vdata, respectively. Searching is illustrated 
  693. in Figure 1.6 in the section example, ╥Reading Data.╙
  694.